package cn.ekuma.epos.datalogic.define.dao.oa;

import cn.ekuma.data.dao.BaseDAO;

import com.openbravo.bean.infobean.UserInfo;
import com.openbravo.bean.oa.Attence;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

import cn.ekuma.epos.db.table.oa.I_Attence;
import cn.ekuma.epos.db.table.oa.Table;

public class AttenceDAO extends BaseDAO<Attence>{

	public AttenceDAO(I_Session s) {
		super(s);
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                Table.OA_ATTENCE,
                new Field[]{
                     new Field(I_Attence.ID,Datas.STRING,Formats.STRING),
                     new Field(I_Attence.CREATEDATE,Datas.TIMESTAMP,Formats.TIMESTAMP),
                     new Field(I_Attence.USER_ID,Datas.STRING,Formats.STRING,UserInfo.class),
                     new Field(I_Attence.ATTENCE_NAME,Datas.STRING,Formats.STRING)   
                    },
                new int[]{0});
	}

	@Override
	public void writeInsertValues(DataWrite dp, Attence obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setTimestamp(2,obj.getCreateDate());
		dp.setString(3,obj.getUserId());
		dp.setString(4,obj.getAttenceName());
	}

	@Override
	public Class getSuportClass() {
		return Attence.class;
	}

	@Override
	public Attence readValues(DataRead dr, Attence obj) throws BasicException {
		if(obj==null)
			obj=new Attence();
		obj.setId(dr.getString(1));
		obj.setCreateDate(dr.getTimestamp(2));
		obj.setUserId(dr.getString(3));
		obj.setAttenceName(dr.getString(4));
		return obj;
	}

}
